#ifndef ROSCLIENT_H
#define ROSCLIENT_H


#include "gSoapFoundation/stdsoap2.h"
#include "gSoapFoundation/rosgsoapnamespaceH.h"
#include "gSoapFoundation/rosgsoapnamespaceStub.h"
//#include "gSoapFoundation/rosgsoapnamespace.nsmap"
#include <string>
#include "../HmiGsoapQt/gSoapFoundation/hmigsoapnamespaceStub.h"

using namespace std;
//using namespace rosgsoapnamespace;
//namespace rosgsoapnamespace {
//class RosClient;
//}

class RosClient
{
public:
    RosClient(string remoteServerAddressIn);


public:

    int changeRemoteServerAddress(string remoteServerAddressIn);
    //***************AGV接口函数部分 hmi->agvBaseControl->ros********************************

    //地图
    int setMapSolver(rosgsoapnamespace::E_MAP_SOLVER solverIn,
                     int laserCount,int &returnFlag);
    int createMapStart(int &returnFlag);
    int createMapEnd(std::string mapName,int &returnFlag);
    int loadMap(std::string mapName,int &returnFlag);

    //添加虚拟墙
    int addVitrualBlock(std::string configFilePath,int &returnFlag);
    int deleteVitrualBlock(int &returnFlag);
    int addForbidenZone(double x_start,double y_start
                        ,double x_end,double y_end,int &returnFlag);

    //定位
    int setOdomSolver(rosgsoapnamespace::E_ODOM_SOLVER solverIn,int &returnFlag);//选择odom enum 方法 int 返回标志
    int setLocationSolver(rosgsoapnamespace::E_MAP_SOLVER solverIn,int &returnFlag);
    int getVehiclePosition(hmigsoapnamespace::VehiclePosition& positionReturn);
    int getVehiclePosition(rosgsoapnamespace::VehiclePosition& positionReturn);
    int setVehiclePosition(hmigsoapnamespace::VehiclePosition positionIn,int &returnFlag);
    int setVehiclePosition(rosgsoapnamespace::VehiclePosition positionIn,int &returnFlag);

    //轨迹规划和行驶
    int setReplanCoutLimitWhenFailure(int countLimit,int &returnFlag);
    int setTrajectoryGlobalPlanSolver(rosgsoapnamespace::E_TRAJECTORY_GLOBAL_SOLVER solverIn,int &returnFlag);//选择全局规划器 enum 全局规划器 int 返回标志
    int setTrajectoryLocalPlanSolver(rosgsoapnamespace::E_TRAJECTORY_LOCAL_SOLVER solverIn,int &returnFlag);//选择局部规划器 enum 局部规划器 int 返回标志
    int moveToPosition(rosgsoapnamespace::VehiclePosition positionIn,
                       double velocity,int &returnFlag);
    int moveToPosition(hmigsoapnamespace::VehiclePosition positionIn,
                       double velocity,int &returnFlag);
    int moveFollowPath(std::vector<hmigsoapnamespace::VehiclePosition> pathIn,
                       double velocity,int &returnFlag);
    int moveFollowPath(std::vector<rosgsoapnamespace::VehiclePosition> pathIn,
                       double velocity,int &returnFlag);
    int changeVelocity(double velocity,int &returnFlag);
    int getMovingStatus(rosgsoapnamespace::E_GOAL_STATUS& status);
    int getRemainningTime(double &timeOut);
    int getRemainningDistance(double &distanceOut);
    int ceaseMotion(int &returnFlag);
    int startMotion(int &returnFlag);
    int cancelMotion(int &returnFlag);

    //设置
    int setPositionArrivedAccuracy(double accuracyIn,int &returnFlag);
    int setLocalPlanRange(double rangeIn,int &returnFlag);
    int setVehicleBorderOffset(std::vector<double> point_x, std::vector<double> point_y,int &returnFlag);
    int setGlobalBarrierOffset(double offsetIn,int &returnFlag);
    int setLocalBarrierOffset(double offsetIn,int &returnFlag);
    int resetRosAll(int &returnFlag);

    //状态
    int getRosPackageStatus(rosgsoapnamespace::E_ROS_PACKAGE package,rosgsoapnamespace:: E_ROS_PACKAGE_STATUS &status);

    //IMU校准
    int startImuCalibrate(int &returnFlag);
    int stopImuCalibrate(int &returnFlag);

    //信息传递
    int getMessage_hmi(std::vector<hmigsoapnamespace::Message> &messageListReturn);
    int getMessage_ros(std::vector<rosgsoapnamespace::Message> &messageListReturn);
    int getVehicleVelocityComand_hmi(int robotIdIn,hmigsoapnamespace::VehicleVelocity &velocityComamnd);
    int getVehicleVelocityComand_ros(int robotIdIn,rosgsoapnamespace::VehicleVelocity &velocityComamnd);
    int setWheelOdometerData_hmi(int robotIdIn, hmigsoapnamespace::OdemeterData odemeterData, int &returnFlag);
    int setWheelOdometerData_ros(int robotIdIn, rosgsoapnamespace::OdemeterData odemeterData, int &returnFlag);
    int setWheelMoveSpeed(int robotIdIn, std::vector<double>wheelMoveSpeed,int &returnFlag);
    int setWheelPathLength(int robotIdIn, std::vector<double>wheelPathLength,int &returnFlag);

private:
    std::vector<rosgsoapnamespace::VehiclePosition> fromHmiData(std::vector<hmigsoapnamespace::VehiclePosition> dataIn);
    rosgsoapnamespace::VehiclePosition fromHmiData(hmigsoapnamespace::VehiclePosition dataIn);
    rosgsoapnamespace::VehicleVelocity fromHmiData(hmigsoapnamespace::VehicleVelocity dataIn);
    rosgsoapnamespace::OdemeterData fromHmiData(hmigsoapnamespace::OdemeterData dataIn);
    hmigsoapnamespace::VehiclePosition fromRosData(rosgsoapnamespace::VehiclePosition dataIn);
    hmigsoapnamespace::VehicleVelocity fromRosData(rosgsoapnamespace::VehicleVelocity dataIn);
    std::vector<hmigsoapnamespace::Message>fromRosData(std::vector<rosgsoapnamespace::Message> dataIn);


private:
    rosgsoapnamespace::UserInfo tmpUserInfo;

    bool isInitialStatus;

    /**
     * @brief client_soap           实例化gsoap通信类
     */
    soap client_soap;
    string remoteServerAddress;

    pthread_mutex_t communicateMutex;
    /**
     * @brief trajAttr 锁参数
     */
    pthread_mutexattr_t mutexAttr;


};

#endif // ROSCLIENT_H
